﻿var contextMenu;

//初始化插件
function init() {
    //定义容器
    var container = document.querySelector('.h-context-menu');
    //定义中心点
    var centerX = container.clientWidth / 2,
        centerY = container.clientHeight / 2;
    //定义层数（几层对应几个数组）		
    var menus_0 = [   // list 
        {      // map
            name: 'NameInfo',           // ennamealias
            caption: '关联',     /// name
            icon: './js/images/relation-ico.png',// 1.png
            rotate: '36',
            top:'-20',
            left:'-77',
            menuList: {                      //  map
                radiusStep: 5,
                //icon: '../images/姓名.png',
                offsetRadius: 48,
                items: [                  // list
                    {
                        name: 'cnName1',
                        caption: '关联事件',
                        //icon: './image/ai.png'
                        rotate: '100',
                        top:'-30',
                        left:'-120',
                        func:function(){
                            relationFun(cxturi,cxtrowkey,'event');
                        }
                    },
                    {
                        name: 'cnName2',
                        caption: '关联实体',
                        //icon: './image/ai.png'
                        rotate: '53',
                        top:'-25',
                        left:'-120',
                        func:function(){
                            relationFun(cxturi,cxtrowkey,'entity');
                        }
                    },
                    {
                        name: 'cnName3',
                        caption: '关联文件',
                        //icon: './image/ai.png'
                        rotate: '7',
                        top:'-22',
                        left:'-120',
                        func:function(){
                            relationFun(cxturi,cxtrowkey,'doc');
                        }
                    },
                    {
                        name: 'cnName4',
                        caption: '关联媒体',
                        //icon: './image/ai.png'
                        rotate: '320',
                        top:'-20',
                        left:'-120',
                        func:function(){
                            relationFun(cxturi,cxtrowkey,'media');
                        }
                    }
                ]
            }
        },
        {      // map
            name: 'NameInfo',           // ennamealias
            caption: '属性',     /// name
            icon: './js/images/look-ico.png',// 1.png  
            rotate: '-90',
            top:'-25',
            left:'-77',
            func: function() {
                window.location.href="obj-show-obj.html";
            },
            menuList: {                      //  map
                
            }
        },
        {      // map
            name: 'NameInfo',           // ennamealias
            caption: '删除关联',     /// name
            icon: './js/images/del-ico.png',// 1.png
            rotate: '-210',
            top:'-20',
            left:'-92',
            menuList: {                      //  map
                radiusStep: 5,
                icon: './image/姓名.png',
                offsetRadius: 48,
                items: [                  // list
                    {
                        name: 'cnName1',
                        caption: '删除自身',
                        //icon: './image/ai.png'
                        rotate: '60',
                        top:'-25',
                        left:'100',
                        func:function(){
                            var j=cy.$('#'+cxtrowkey);
                            cy.remove(j);
                            graph=cy.json();
                        }
                    },
                    {
                        name: 'cnName2',
                        caption: '删除关联事件',
                        //icon: './image/ai.png'
                        rotate: '15',
                        top:'-25',
                        left:'95',
                        func:function(){
                            relationDel(cxturi,cxtrowkey,'event');
                        }
                    },
                    {
                        name: 'cnName3',
                        caption: '删除关联实体',
                        //icon: './image/ai.png'
                        rotate: '-32',
                        top:'-25',
                        left:'95',
                        func:function(){
                            relationDel(cxturi,cxtrowkey,'entity');
                        }
                    },
                    {
                        name: 'cnName4',
                        caption: '删除关联文件',
                        //icon: './image/ai.png'
                        rotate: '-75',
                        top:'-25',
                        left:'95',
                        func:function(){
                            relationDel(cxturi,cxtrowkey,'doc');
                        }
                    },
                    {
                        name: 'cnName5',
                        caption: '删除关联媒体',
                        //icon: './image/ai.png'
                        rotate: '-120',
                        top:'-25',
                        left:'95',
                        func:function(){
                            relationDel(cxturi,cxtrowkey,'media');
                        }
                    }
                ]
            }
        }
    ];

    contextMenu = new HERE.UI.AnnularMenu({
        menuList: {
            offsetRadius: 48,
            items: menus_0
        }
    });
    //定义中心点
    var element = contextMenu.render({
        x: posx,
        y: posy
    });
    //绑定事件
    var D = $(document).data('func', {});
    contextMenu.addEventListener('menuClick', function (e) {
        var tempFun=e.data.func;
        tempFun();
        var target = e.target;
        contextMenu.selectMenuEl(target);
        $('.ctxmenu').html('');
    });
    //将中心点放到页面上
    container.appendChild(element);
}
